<?php 
Class Gold_Digg_Model_Mysql4_Digg_Product extends Mage_Core_Model_Mysql4_Abstract{

  protected function _construct(){
  
      $this->_init('digg/digg_product','product_id');
      $this->_isPkAutoIncrement = false;
      $this->_useIsObjectNew = true;
  }
  public function loadByProductAndIP($productId,$remoteAddr){
     
      $select = $this->_getReadAdapter()->select()->from($this->getTable('digg/digg_product'))
          ->where('product_id=:product_id')->where('remote_addr=:remote_addr');
      return $this->_getReadAdapter()->fetchRow($select,array('product_id'=>$productId,'remote_addr'=>$remoteAddr)); 
  }
  public function save(Mage_Core_Model_Abstract $object){
     $select = $this->_getWriteAdapter()->select()
                    ->from($this->getMainTable(), array($this->getIdFieldName()))
                    ->where($this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()))
                    ->where( $this->_getWriteAdapter()->quoteInto('remote_addr'.'=?', $object->getRemoteAddr()));
     if ($this->_getWriteAdapter()->fetchOne($select) === false) { 
        $object->isObjectNew(true);
     }
    return parent::save($object);
  }
}
